﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TravianHelper.app;
using System.Threading;

namespace TravianHelper
{
    public partial class AttackForm : Form
    {
        public int[,] attacks;
        bool startPlan = false;
        int n;
        Thread[] threads;

        public AttackForm()
        {
            InitializeComponent();
        }

        private void AttackForm_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            n = Convert.ToInt32(textBoxNumber.Text);
            attacks = new int [n,14];
            dataGrid1.DataSource = new Mommo.Data.ArrayDataView(attacks, new string[] {"Main wave?", "T1", "T2", "T3", "T4", "T5", "T6", "Ram", "Cata", "Chief", "Settler", "Hero", "Target1", "Target2" });
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label3.Text = "Current time: " + DateTime.Now.Hour+":"+DateTime.Now.Minute+":"+DateTime.Now.Second;
            if (startPlan && textBoxH.Text == DateTime.Now.Hour.ToString() && textBoxM.Text == DateTime.Now.Minute.ToString() && textBoxS.Text == DateTime.Now.Second.ToString())
            {
                startPlan = false;
                TravianApplicationContext.adapter.launchMassAttack(threads);
            }
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            startPlan = true;
        }

        private void buttonPrepare_Click(object sender, EventArgs e)
        {
            threads = TravianApplicationContext.adapter.prepareMassAttack(n, attacks, textBoxX.Text, textBoxY.Text);
            if (threads.Length > 0)
            {
                MessageBox.Show("All attacks ready");
            }
            else
            {
                MessageBox.Show("Error. Please try again");
            }
        }

    }
}
